package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 16
 * Time:19:31
 */

/***
 * 判断链表是否有环——快慢指针能相遇则说明有环
 */
public class Test11 {
    public boolean hasCycle(ListNode head){
        if(head==null)
            return false;
        ListNode fast=head;
        ListNode slow=head;
        while(fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            if(fast==slow)
                return true;
        }
        return false;
    }
}
